<?php
	declare (strict_types=1);

	namespace app\middleware;

	use app\lib\enums\ApiCodeEnums;
	use think\Request;

	class CheckMember
	{
		/**
		 * 处理请求
		 *
		 * @param \think\Request $request
		 * @param \Closure       $next
		 *
		 * @return Response
		 */
		public function handle ($request, \Closure $next) {
			if (!$request->header('token')) {
				return toast('欢迎进入,请先登录', ApiCodeEnums::NOT_LOGIN);
			}

			if ($request->header('token') != '123456') {
				return toast('欢迎进入,用户信息已过期,请登录', -2);
			}

			$member = ['username' => '张三', 'mobile' => 13053055130, 'sex' => 'man'];
			$members = ['id' => 19, 'username' => '李四', 'mobile' => 13053055190, 'sex' => 'man'];

			Request::macro('member', function () use ($members) {
				return $members;
			});

			Request::macro('uid', function () use ($members) {
				return $members['id'];
			});

			$request->member = $member;

			return $next($request);
		}
	}
